﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace kpi.MasterManager
{
    public partial class KpiInfoMgr : System.Web.UI.Page
    {
        //Decimal _u_kpi_rat = 0m; 

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                //月份下拉列表
                DropDownList_SelectMonth_AddItems();

                //用户名下拉列表
                DropDownList_SelectUser_AddItems();

                // 显示KPI信息
                // 默认显示当前月份的信息
                //GridView_ShowKpiInfo_DataBind();

                //显示说明信息
                Label_UserGuide.Text = "<br />";
                Label_UserGuide.Text += "<fieldset>";
                Label_UserGuide.Text += "<legend>说明</legend>";
                Label_UserGuide.Text += "<ol>";
                //Label_UserGuide.Text += "<li>新用户首次使用该系统，首先应当注册用户账户；已经注册账户的用户，请进行登录。</li>";
                //Label_UserGuide.Text += "<li>系统中的账户只分为“管理者账户”和“一般账户”两种，区别是“管理者账户”可以对所管理的“一般账户”进行查看和评分。</li>";
                Label_UserGuide.Text += "<li>KPI历史信息以用户录入日期为准。</li>";
                Label_UserGuide.Text += "</ol>";
                Label_UserGuide.Text += "</fieldset>";
                Label_UserGuide.Visible = true;
            }
        }

        protected String GetSqlConnectionString()
        {
            return "Data Source=192.168.0.241;Initial Catalog=kpi_forms_db;Persist Security Info=True;User ID=sa;Password=My.SA";
        }

        protected SqlConnection GetSqlConnection(String SqlConnectionString)
        {
            SqlConnection SqlConnection = new SqlConnection(GetSqlConnectionString());
            return SqlConnection;
        }

        // 默认显示当前月份KPI信息（用户录入日期为准）。
        protected String GetSqlCommand(String commandType, String UserName)
        {
            switch (commandType)
            {
                case "select":
                    //return "SELECT [id], [UserName], [u_kpi] ,[u_kpi_std] ,[u_kpi_comm] ,[u_kpi_rat] ,[u_kpi_fx] ,[uM_kpi_rec] ,[u_kpi_ref], [u_Kpi_ins_datetime] FROM [kpi_forms_db].[dbo].[u_kpi_table] WHERE [Username]='" + UserName + "' AND u_kpi_ins_datetime >= (SELECT DATEADD(MONTH, DATEDIFF(MONTH,0,getdate()), 0)) AND [u_kpi_conf] = 1";
                    return "SELECT [id], [UserName], [u_kpi] ,[u_kpi_std] ,[u_kpi_comm] ,[u_kpi_rat] ,[u_kpi_fx] ,[uM_kpi_rec] ,[u_kpi_ref], [u_Kpi_ins_datetime] FROM [kpi_forms_db].[dbo].[u_kpi_table] WHERE u_kpi_ins_datetime >= (SELECT DATEADD(MONTH, DATEDIFF(MONTH,0,getdate()), 0)) AND [u_kpi_conf] = 1 ORDER BY UserName";

                case "insert":
                    return "INSERT INTO u_kpi_table (id, UserName, u_kpi, u_kpi_std, u_kpi_comm, u_kpi_rat, u_kpi_fx, uM_kpi_rec, u_kpi_ref) VALUES "
        + " (@id, @UserName, @u_kpi, @u_kpi_std, @u_kpi_comm, @u_kpi_rat, @u_kpi_fx, @u_kpi_rec, @uM_kpi_rec, @u_kpi_ref)";

                case "update":
                    return "UPDATE [u_kpi_table] SET [u_kpi_conf]=@u_kpi_conf WHERE [UserName]=@UserName";

                default:
                    return "";
            }
        }

        //以用户确认KPI录入时间为准
        // u_kpi_conf     = 0 用户未确认录入KPI
        // u_kpi_conf     = 1 用户已确认录入KPI
        // u_kpi_conf_datetime  : 用户确认KPI录入时间
        //---------------------------------------------
        // u_kpi_doneconf        = 0 用户未确认KPI完成
        // u_kpi_doneconf        = 1 用户已确认KPI完成
        // u_kpi_done_datetime   : 用户确认KPI完成时间
        //---------------------------------------------
        // uM_kpi_rec    : 用户考评得分
        protected void DropDownList_SelectMonth_AddItems()
        {
            SqlConnection SqlConnection = GetSqlConnection(null);
            SqlConnection.Open();

            //SqlCommand selectCommand = new SqlCommand("SELECT DISTINCT CONVERT(nvarchar, YEAR(u_kpi_conf_datetime))+'-'+ CONVERT(nvarchar, MONTH(u_kpi_conf_datetime)) FROM [dbo].[u_kpi_table] WHERE u_kpi_conf_datetime IS NOT NULL", SqlConnection);
            SqlCommand SelectCommand = new SqlCommand("SELECT DISTINCT CONVERT(nvarchar, YEAR(u_kpi_conf_datetime))+'-0'+ CONVERT(nvarchar, MONTH(u_kpi_conf_datetime)) AS YearMonth FROM [dbo].[u_kpi_table] WHERE u_kpi_conf_datetime IS NOT NULL ORDER BY YearMonth DESC", SqlConnection);

            SqlDataReader YearMonthReader = SelectCommand.ExecuteReader();

            while (YearMonthReader.Read())
            {
                DropDownList_SelectMonth.Items.Add(new ListItem(YearMonthReader["YearMonth"].ToString(), YearMonthReader["YearMonth"].ToString() + "-01"));
                //DropDownList_SelectMonth.Items.Add(new ListItem(YearMonthReader[0].ToString(), YearMonthReader[1].ToString()));
            }

            //处理无满足条件
            if (YearMonthReader.HasRows)
            {
                Label_HisInfoMsg.Visible = true;
                DropDownList_SelectMonth.Visible = true;
                Button_ShowHisInfo.Visible = true;
            }
            else
            {
                Label_HisInfoMsg.Visible = false;
                DropDownList_SelectMonth.Visible = false;
                Button_ShowHisInfo.Visible = false;
            }

            YearMonthReader.Dispose();
            YearMonthReader.Close();
            SelectCommand.Dispose();
            SqlConnection.Close();
        }

        protected void DropDownList_SelectUser_AddItems()
        {
            DropDownList_SelectUser.Dispose();
            DropDownList_SelectUser.Items.Add(new ListItem("全部", "all"));

            SqlConnection SqlConnection = new SqlConnection("Data Source=192.168.0.241;Initial Catalog=kpi_forms_db;Persist Security Info=True;User ID=sa;Password=My.SA");
            SqlConnection.Open();

            //String selectCommand = "SELECT DISTINCT UserName FROM [dbo].[u_kpi_table] WHERE UserName IN ( SELECT UserName FROM [u_kpi_userInManager] WHERE uManagerName='" + User.Identity.Name + "') ORDER BY UserName";
            //显示全部用户名
            String selectCommand = "SELECT DISTINCT UserName FROM [dbo].[u_kpi_table] ORDER BY UserName";

            SqlCommand SelectCommand = new SqlCommand(selectCommand, SqlConnection);
            SqlDataReader RoleNameReader = SelectCommand.ExecuteReader();

            while (RoleNameReader.Read())
            {
                DropDownList_SelectUser.Items.Add(new ListItem(RoleNameReader["UserName"].ToString(), RoleNameReader["UserName"].ToString()));
            }

            SqlConnection.Close();
        }

        protected void Button_ShowHisInfo_Click(object sender, EventArgs e)
        {
            GridView_ShowKpiInfo.EmptyDataText = "抓住一个，他还没录入！";

            //获取月份
            String SelectedMonth = DropDownList_SelectMonth.SelectedValue;

            //获取用户名
            String SelectedUserName = DropDownList_SelectUser.SelectedValue;

            GridView_ShowKpiInfo.Dispose();
            GridView_ShowKpiInfo.Columns.Clear();

            //GridView_ShowHisKpiInfo_DataBind(SelectedUserName, SelectedMonth);
            GridView_ShowKpiInfo_DataBind(SelectedUserName, SelectedMonth);

            //显示页脚权重合计
            //应在Bind()方法内调用
            //GridView_ShowKpiInfo_BuildFooter();
        }

        protected DataSet ShowKpiInfoDataSet(String SelectedUserName, String SelectedMonth)
        {
            String SelectCommand;

            DataSet UserKpiFormDataSet = new DataSet();

            SqlConnection SqlConnection = GetSqlConnection(null);
            SqlConnection.Open();

            if (SelectedUserName.Equals("all"))
            {
                SelectCommand = "SELECT [id], [UserName], [u_kpi], [u_kpi_std], [u_kpi_comm], [u_kpi_rat], [u_kpi_fx], [uM_kpi_rec], [u_kpi_ref], [u_kpi_m], [u_Kpi_ins_datetime] FROM [kpi_forms_db].[dbo].[u_kpi_table] WHERE u_kpi_ins_datetime BETWEEN (SELECT DATEADD(MONTH, DATEDIFF(MONTH,0,'" + SelectedMonth + "'), 0)) AND (SELECT DATEADD(ms,-1,DATEADD(mm, DATEDIFF(m,0,'" + SelectedMonth + "')+1, 0))) AND [u_kpi_conf] = 1 ORDER BY UserName";
            }
            else
            {
                // 注意，这是个复杂的SQL语句           
                SelectCommand = "SELECT [id], [UserName], [u_kpi], [u_kpi_std], [u_kpi_comm], [u_kpi_rat], [u_kpi_fx], [uM_kpi_rec], [u_kpi_ref], [u_kpi_m], [u_Kpi_ins_datetime] FROM [kpi_forms_db].[dbo].[u_kpi_table] WHERE [Username]='" + SelectedUserName + "' AND u_kpi_ins_datetime BETWEEN (SELECT DATEADD(MONTH, DATEDIFF(MONTH,0,'" + SelectedMonth + "'), 0)) AND (SELECT DATEADD(ms,-1,DATEADD(mm, DATEDIFF(m,0,'" + SelectedMonth + "')+1, 0))) AND [u_kpi_conf] = 1";
            }

            SqlDataAdapter dataAdapter = new SqlDataAdapter(SelectCommand, SqlConnection);
            //
            dataAdapter.Fill(UserKpiFormDataSet);
            //dataAdapter.Fill(UserKpiFormDataTable);

            //GridView_UserKpiForm.DataSource = dataAdapter;
            //GridView_UserKpiForm.DataKeyNames = new string[] { "id" };//主键
            //GridView_UserKpiForm.DataBind();

            dataAdapter.Dispose();

            SqlConnection.Close();

            return UserKpiFormDataSet;
        }

        protected DataSet ShowKpiHisInfoDataSet(String SelectedUserName, String SelectedMonth)
        {
            //String yearMonth = DropDownList_SelectMonth.SelectedValue;

            String SelectCommand;

            DataSet UserKpiFormHisDataSet = new DataSet();
            SqlConnection SqlConnection = GetSqlConnection(null);
            SqlConnection.Open();

            if (SelectedUserName.Equals("all"))
            {
                SelectCommand = "SELECT [id], [UserName], [u_kpi], [u_kpi_std], [u_kpi_comm], [u_kpi_rat], [u_kpi_fx], [uM_kpi_rec], [u_kpi_ref], [u_Kpi_ins_datetime],[u_kpi_done_comm] FROM [kpi_forms_db].[dbo].[u_kpi_table] WHERE [Username]='" + SelectedUserName + "' AND u_kpi_ins_datetime BETWEEN (SELECT DATEADD(MONTH, DATEDIFF(MONTH,0,'" + SelectedMonth + "'), 0)) AND (SELECT DATEADD(ms,-1,DATEADD(mm, DATEDIFF(m,0,'" + SelectedMonth + "')+1, 0))) AND [u_kpi_conf] = 1";
            }
            else
            {

                // 注意，这是个复杂的SQL语句           
                SelectCommand = "SELECT [id], [UserName], [u_kpi], [u_kpi_std], [u_kpi_comm], [u_kpi_rat], [u_kpi_fx], [uM_kpi_rec], [u_kpi_ref], [u_Kpi_ins_datetime],[u_kpi_done_comm] FROM [kpi_forms_db].[dbo].[u_kpi_table] WHERE [Username]='" + SelectedUserName + "' AND u_kpi_ins_datetime BETWEEN (SELECT DATEADD(MONTH, DATEDIFF(MONTH,0,'" + SelectedMonth + "'), 0)) AND (SELECT DATEADD(ms,-1,DATEADD(mm, DATEDIFF(m,0,'" + SelectedMonth + "')+1, 0))) AND [u_kpi_conf] = 1";
            }

            SqlDataAdapter dataAdapter = new SqlDataAdapter(SelectCommand, SqlConnection);

            dataAdapter.Fill(UserKpiFormHisDataSet);

            dataAdapter.Dispose();

            SqlConnection.Close();

            return UserKpiFormHisDataSet;
        }

        protected void GridView_ShowKpiInfo_DataBind(String SelectedUserName, String SelectedMonth)
        {
            GridView_ShowKpiInfo.AutoGenerateColumns = false;

            GridView_ShowKpiInfo.DataSource = ShowKpiInfoDataSet(SelectedUserName, SelectedMonth);
            GridView_ShowKpiInfo.DataKeyNames = new string[] { "id" };

            BoundField bField;
            bField = new BoundField();
            bField.DataField = "id";
            bField.HeaderText = "编号";
            bField.ReadOnly = true;
            GridView_ShowKpiInfo.Columns.Add(bField);

            bField = new BoundField();
            bField.DataField = "UserName";
            bField.HeaderText = "姓名";
            bField.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
            bField.HeaderStyle.Wrap = false;
            bField.ReadOnly = true;
            bField.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
            //bField.ItemStyle.Width = 20;
            bField.ItemStyle.Wrap = false;
            GridView_ShowKpiInfo.Columns.Add(bField);

            bField = new BoundField();
            bField.DataField = "u_kpi";
            bField.HeaderText = "KPI明细";
            bField.ReadOnly = true;
            GridView_ShowKpiInfo.Columns.Add(bField);

            bField = new BoundField();
            bField.DataField = "u_kpi_std";
            bField.HeaderText = "KPI数值/内容";
            bField.ReadOnly = true;
            GridView_ShowKpiInfo.Columns.Add(bField);

            bField = new BoundField();
            bField.DataField = "u_kpi_comm";
            bField.HeaderText = "KPI说明";
            bField.ReadOnly = true;
            GridView_ShowKpiInfo.Columns.Add(bField);

            bField = new BoundField();
            bField.DataField = "u_kpi_rat";
            bField.HeaderText = "KPI权重";
            bField.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
            bField.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
            bField.HeaderStyle.Wrap = false;
            bField.ReadOnly = true;
            GridView_ShowKpiInfo.Columns.Add(bField);

            bField = new BoundField();
            bField.DataField = "u_kpi_fx";
            bField.HeaderText = "KPI公式";
            bField.ReadOnly = true;
            GridView_ShowKpiInfo.Columns.Add(bField);

            bField = new BoundField();
            bField.DataField = "u_kpi_ref";
            bField.HeaderText = "KPI实际数值/内容";
            bField.HeaderStyle.Wrap = false;
            bField.ReadOnly = true;
            GridView_ShowKpiInfo.Columns.Add(bField);

            //bField = new BoundField();
            //bField.DataField = "u_kpi_done_comm";
            //bField.HeaderText = "KPI完成情况说明";
            //bField.ReadOnly = true;
            //bField.HeaderStyle.Wrap = false;
            //GridView_ShowKpiInfo.Columns.Add(bField);

            bField = new BoundField();
            bField.DataField = "uM_kpi_rec";
            bField.HeaderText = "KPI考评得分";
            bField.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
            bField.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
            bField.HeaderStyle.Wrap = false;
            bField.ReadOnly = true;
            GridView_ShowKpiInfo.Columns.Add(bField);

            bField = new BoundField();
            bField.DataField = "u_kpi_m";
            bField.HeaderText = "KPI考评人";
            bField.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
            bField.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
            bField.HeaderStyle.Wrap = false;
            bField.ReadOnly = true;
            GridView_ShowKpiInfo.Columns.Add(bField);

            bField = new BoundField();
            bField.DataField = "u_kpi_ins_datetime";
            bField.HeaderText = "用户录入日期";
            bField.HeaderStyle.Wrap = false;
            bField.ReadOnly = true;
            GridView_ShowKpiInfo.Columns.Add(bField);

            GridView_ShowKpiInfo.Columns[0].Visible = false;

            GridView_ShowKpiInfo.DataBind();

            //显示页脚合计
            GridView_ShowKpiInfo_BuildFooter();           
        }

        protected void GridView_ShowHisKpiInfo_DataBind(String SelectedUserName, String SelectedMonth)
        {
            //清除所有列，避免重复显示
            GridView_ShowKpiInfo.Columns.Clear();

            GridView_ShowKpiInfo.AutoGenerateColumns = false;

            GridView_ShowKpiInfo.DataSource = ShowKpiHisInfoDataSet(SelectedUserName, SelectedMonth);
            GridView_ShowKpiInfo.DataKeyNames = new string[] { "id" };

            BoundField bField;
            bField = new BoundField();
            bField.DataField = "id";
            bField.HeaderText = "编号";
            bField.ReadOnly = true;
            GridView_ShowKpiInfo.Columns.Add(bField);

            bField = new BoundField();
            bField.DataField = "UserName";
            bField.HeaderText = "姓名";
            bField.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
            bField.HeaderStyle.Wrap = false;
            bField.ReadOnly = true;
            bField.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
            //bField.ItemStyle.Width = 20;
            bField.ItemStyle.Wrap = false;
            GridView_ShowKpiInfo.Columns.Add(bField);

            bField = new BoundField();
            bField.DataField = "u_kpi";
            bField.HeaderText = "KPI明细";
            bField.ReadOnly = true;
            GridView_ShowKpiInfo.Columns.Add(bField);

            bField = new BoundField();
            bField.DataField = "u_kpi_std";
            bField.HeaderText = "KPI数值/内容";
            bField.ReadOnly = true;
            GridView_ShowKpiInfo.Columns.Add(bField);

            bField = new BoundField();
            bField.DataField = "u_kpi_comm";
            bField.HeaderText = "KPI说明";
            bField.ReadOnly = true;
            GridView_ShowKpiInfo.Columns.Add(bField);

            bField = new BoundField();
            bField.DataField = "u_kpi_rat";
            bField.HeaderText = "KPI权重";
            bField.ReadOnly = true;
            GridView_ShowKpiInfo.Columns.Add(bField);

            bField = new BoundField();
            bField.DataField = "u_kpi_fx";
            bField.HeaderText = "KPI公式";
            bField.ReadOnly = true;
            GridView_ShowKpiInfo.Columns.Add(bField);

            bField = new BoundField();
            bField.DataField = "u_kpi_ref";
            bField.HeaderText = "KPI实际数值/内容";
            bField.ReadOnly = true;
            GridView_ShowKpiInfo.Columns.Add(bField);

            //取消KPI自评分
            //bField = new BoundField();
            //bField.DataField = "u_kpi_rec";
            //bField.HeaderText = "KPI自评得分";
            //bField.ReadOnly = true;
            //GridView_ShowKpiInfo.Columns.Add(bField);

            bField = new BoundField();
            bField.DataField = "uM_kpi_rec";
            bField.HeaderText = "KPI考评得分";
            //bField.ReadOnly = true;
            GridView_ShowKpiInfo.Columns.Add(bField);

            bField = new BoundField();
            bField.DataField = "u_kpi_ins_datetime";
            bField.HeaderText = "用户录入日期";
            //bField.ReadOnly = true;
            GridView_ShowKpiInfo.Columns.Add(bField);

            GridView_ShowKpiInfo.Columns[0].Visible = false;

            GridView_ShowKpiInfo.DataBind();
        }

        protected void ShowUnInsKpiUserNames()
        {
            Label_ShowUnInsKpiUserNames.Text = "当月未录入KPI信息的用户有：";
            Label_ShowUnInsKpiUserNames.Text += "<br />";

            SqlConnection SqlConnection = GetSqlConnection(null);
            SqlConnection.Open();

            String SelectCommandString = "SELECT UserName FROM [kpi_aspnet_db].[dbo].[aspnet_Users] WHERE UserName NOT IN (SELECT UserName FROM [kpi_forms_db].[dbo].[u_kpi_table] WHERE [u_kpi_ins_datetime]>=DATEADD(MONTH, DATEDIFF(MONTH,0,getdate()), 0)) AND UserName NOT LIKE '测试%' AND UserName NOT LIKE '%o%' AND UserName NOT LIKE '用户%' AND UserName NOT LIKE '账户%' ORDER BY UserName";

            SqlCommand SelectCommand = new SqlCommand(SelectCommandString, SqlConnection);
            SqlDataReader RoleNameReader = SelectCommand.ExecuteReader();

            while (RoleNameReader.Read())
            {
                Label_ShowUnInsKpiUserNames.Text += RoleNameReader["UserName"].ToString() + "，";
            }

            Label_ShowUnInsKpiUserNames.Text += "<br />";

            RoleNameReader.Dispose();
            RoleNameReader.Close();
            SelectCommand.Dispose();
            SqlConnection.Close();
        }

        protected void ShowUnSumKpiRateUserNames()
        {
            Label_ShowUnInsKpiUserNames.Text += "<br />";
            Label_ShowUnInsKpiUserNames.Text += "用户已确认KPI信息，但当月权重合计值异常的用户有：";
            Label_ShowUnInsKpiUserNames.Text += "<br />";

            SqlConnection SqlConnection = GetSqlConnection(null);
            SqlConnection.Open();

            String SelectCommandString = "SELECT UserName, SUM(u_kpi_rat) AS SumRate FROM [kpi_forms_db].[dbo].[u_kpi_table] WHERE [u_kpi_ins_datetime]>=DATEADD(MONTH, DATEDIFF(MONTH,0,getdate()), 0) AND [u_kpi_conf] = 1 GROUP BY UserName HAVING SUM(u_kpi_rat)<>100";

            SqlCommand SelectCommand = new SqlCommand(SelectCommandString, SqlConnection);
            SqlDataReader RoleNameReader = SelectCommand.ExecuteReader();

            while (RoleNameReader.Read())
            {
                Label_ShowUnInsKpiUserNames.Text += RoleNameReader["UserName"].ToString() + "（" + RoleNameReader["SumRate"].ToString() + "），";
            }

            Label_ShowUnInsKpiUserNames.Text += "<br />";

            RoleNameReader.Dispose();
            RoleNameReader.Close();
            SelectCommand.Dispose();
            SqlConnection.Close();
        }

        protected void ShowUnMrecKpiUserName()
        {
            Label_ShowUnInsKpiUserNames.Text += "<br />";
            Label_ShowUnInsKpiUserNames.Text += "上月没有考评得分用户有：";
            Label_ShowUnInsKpiUserNames.Text += "<br />";

            SqlConnection SqlConnection = GetSqlConnection(null);
            SqlConnection.Open();

            String SelectCommandString = "SELECT DISTINCT UserName FROM [kpi_forms_db].[dbo].[u_kpi_table] WHERE [u_kpi_ins_datetime]<DATEADD(MONTH, DATEDIFF(MONTH,0,getdate()), 0) AND [uM_kpi_rec]='0'";

            SqlCommand SelectCommand = new SqlCommand(SelectCommandString, SqlConnection);
            SqlDataReader RoleNameReader = SelectCommand.ExecuteReader();

            while (RoleNameReader.Read())
            {
                Label_ShowUnInsKpiUserNames.Text += RoleNameReader["UserName"].ToString() + "，";
            }

            Label_ShowUnInsKpiUserNames.Text += "<br />";

            RoleNameReader.Dispose();
            RoleNameReader.Close();
            SelectCommand.Dispose();
            SqlConnection.Close();
        }

        protected void Button_ShowIsuKpi_Click(object sender, EventArgs e)
        {
            Label_ShowUnInsKpiUserNames.Text = "";

            //显示未录入任何KPI信息的用户名
            ShowUnInsKpiUserNames();

            //显示KPI权重合计值<>100的用户名
            ShowUnSumKpiRateUserNames();

            //显示考评分为0的用户
            ShowUnMrecKpiUserName();

            Label_ShowUnInsKpiUserNames.Visible = true;
        }

        protected void GridView_ShowKpiInfo_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            Decimal _u_kpi_rat = 0m;

            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                DataRowView TotalRows = (System.Data.DataRowView)e.Row.DataItem;

                for (int i = 0; i < GridView_ShowKpiInfo.HeaderRow.Cells.Count; i++)
                {
                    if (GridView_ShowKpiInfo.HeaderRow.Cells[i].Text.Equals("KPI权重"))
                    {
                        e.Row.Cells[i].HorizontalAlign = HorizontalAlign.Center;
                        _u_kpi_rat += Convert.ToDecimal(TotalRows[i].ToString());
                    }
                }
            }
            else if (e.Row.RowType == DataControlRowType.Footer)
            {
                e.Row.Cells[1].HorizontalAlign = HorizontalAlign.Right;
                e.Row.Cells[1].Text = "合计：";

                for (int i = 0; i < GridView_ShowKpiInfo.HeaderRow.Cells.Count; i++)
                {
                    if (GridView_ShowKpiInfo.HeaderRow.Cells[i].Text.Equals("KPI权重"))
                    {
                        //如果当前权重合计>=100，则阻止用户继续录入
                        //if (_u_kpi_rat > 100)
                        //{
                        //    Button_Cf_Kpi_info.Visible = false;
                        //    Button_UserConf.Visible = false;
                        //    Label_ErrorMsg.ForeColor = Color.Red;
                        //    Label_ErrorMsg.Text = "<br /><br />权重合计值已经等于100，无法继续录入以及确认KPI信息！如需继续，请修改已录入的KPI信息。<br /><br />";
                        //    Label_ErrorMsg.Visible = true;
                        //}
                        //else
                        //{
                        //    Button_Cf_Kpi_info.Visible = true;
                        //    Button_UserConf.Visible = true;

                        //    Label_ErrorMsg.Visible = false;
                        //}
                        //Label_SumInsKpiRat.Text = _u_kpi_rat.ToString();
                        e.Row.Cells[i].Text = _u_kpi_rat.ToString();
                        e.Row.Cells[i].HorizontalAlign = HorizontalAlign.Center;
                    }
                }
            }
        }

        protected void GridView_ShowKpiInfo_BuildFooter()
        {
            //Label_DebugMsg.Text = GridView_ShowKpiInfo.HeaderRow.Cells.Count.ToString();
            //Label_DebugMsg.Text = GridView_ShowKpiInfo.Rows.Count.ToString();

            //必须判断GridView是否为空，否则抛出"System.NullReferenceException"类型的异常
            if (GridView_ShowKpiInfo.Rows.Count > 0)
            {
                Decimal _u_kpi_rat = 0m;
                Decimal _uM_kpi_rec = 0m;

                for (int i = 0; i < GridView_ShowKpiInfo.Rows.Count; i++)
                {
                    if (GridView_ShowKpiInfo.Rows[i].RowType == DataControlRowType.DataRow)
                    {
                        _u_kpi_rat += Convert.ToDecimal(GridView_ShowKpiInfo.Rows[i].Cells[5].Text);
                        _uM_kpi_rec += Convert.ToDecimal(GridView_ShowKpiInfo.Rows[i].Cells[8].Text);
                    }
                }

                GridView_ShowKpiInfo.FooterRow.Cells[1].Wrap = false;
                GridView_ShowKpiInfo.FooterRow.Cells[1].HorizontalAlign = HorizontalAlign.Center;
                GridView_ShowKpiInfo.FooterRow.Cells[1].Text = "合计：";
                GridView_ShowKpiInfo.FooterRow.Cells[5].HorizontalAlign = HorizontalAlign.Center;
                GridView_ShowKpiInfo.FooterRow.Cells[5].Text = _u_kpi_rat.ToString();
                GridView_ShowKpiInfo.FooterRow.Cells[8].HorizontalAlign = HorizontalAlign.Center;
                GridView_ShowKpiInfo.FooterRow.Cells[8].Text = _uM_kpi_rec.ToString();
            }
        }

        protected void Button_HidIsuKpi_Click(object sender, EventArgs e)
        {
            Label_ShowUnInsKpiUserNames.Text = "";
            Label_ShowUnInsKpiUserNames.Visible = false;
        }
    }
}